package com.i5tong.greendaodemo.utils;

import android.content.Context;

import com.i5tong.greendaodemo.dao.DaoMaster;
import com.i5tong.greendaodemo.dao.DaoSession;


/**
 * Created by Steven on 15-5-10.
 */
public class DbUtils {
    private static DaoMaster daoMaster;
    private static DaoSession daoSession;

    /**
     * 取得DaoSession
     *
     * @param context
     * @return
     */
    public static DaoSession getDaoSession(Context context, String DATABASE_NAME) {
        if (daoMaster == null) {
            DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(context, DATABASE_NAME, null);
            daoMaster = new DaoMaster(helper.getWritableDatabase());
        }

        if (daoSession == null) {
            daoSession = daoMaster.newSession();
        }

        return daoSession;
    }

}
